<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>美兰数据文化馆与图书馆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
</head>
<style>
    /* 底部固定区域 */
    .layui-layout-admin .layui-footer {
        padding: 10px 0;
        text-align: center;
    }

    .layui-layout-admin .layui-footer {
        background-color: #fff;
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-tab-content" style="height: auto">
                <form class="layui-form" lay-filter="component-form-element" action="">
                    <input type="hidden" name="id" id="id">
                    <input type="hidden" name="change" value="yes">
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">序号</label>
                                <div class="layui-input-block">
                                    <input type="number" name="oderNumber" lay-verify="oderNumber" id="oderNumber"
                                           autocomplete="off" placeholder="请输入序号" class="layui-input"  oninput="value=value.replace(/[^\d]+/g,'')">
                                </div>
                            </div>
                            <div class="layui-col-xs1">
                                <div class="layui-form-mid layui-word-aux"
                                     style="color: red !important;padding: 10px !important;">*
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">属性名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="displayName" lay-verify="displayName" id="displayName"
                                           autocomplete="off" placeholder="请输入属性名称" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs1">
                                <div class="layui-form-mid layui-word-aux"
                                     style="color: red !important;padding: 10px !important;">*
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">属性代码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" lay-verify="name" id="name" disabled
                                           autocomplete="off"
                                           placeholder="请输入属性代码" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs1">
                                <div class="layui-form-mid layui-word-aux"
                                     style="color: red !important;padding: 10px !important;">*
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">属性类型</label>
                            <div class="layui-input-block">
                                <input type="radio" lay-filter="typeradio" disabled name="type" value="input"
                                       title="输入框"
                                       checked>
                                <input type="radio" lay-filter="typeradio" disabled name="type" value="select"
                                       title="单选下拉框">
                                <input type="radio" lay-filter="typeradio" disabled name="type" value="selects"
                                       title="多选下拉框">
                                <input type="radio" lay-filter="typeradio" disabled name="type" value="datetime"
                                       title="时间框">
                                <input type="radio" lay-filter="typeradio" disabled name="type" value="textarea"
                                       title="文本框">
                                <input type="radio" lay-filter="typeradio" disabled name="type" value="radio"
                                       title="单选框">
                                <input type="radio" lay-filter="typeradio" disabled name="type" value="checkbox"
                                       title="复选框">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">数据类型</label>
                                <div class="layui-input-block">
                                    <select name="dataType" id="dataType" lay-filter="LAY-user-adminrole-type">
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">日期格式</label>
                            <div class="layui-input-block">
                                <input type="radio" name="dateformat" value="0" title="yyyy-MM-dd" checked>
                                <input type="radio" name="dateformat" value="1" title="yyyy年MM月dd日">
                                <input type="radio" name="dateformat" value="2" title="yyyy-MM-dd HH:mm:ss">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">是否显示</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="state" lay-skin="switch" lay-text="是|否"
                                       lay-filter="switchstate">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">是否验证</label>
                            <div class="layui-input-block" id="isValidates">
                                <input type="checkbox" name="isValidate" id="isValidate" lay-skin="switch"
                                       lay-text="是|否"
                                       lay-filter="switchisValidate">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">表格属性</label>
                            <div class="layui-input-block" id="headradios">
                                <input type="checkbox" name="head" id="headradio" lay-skin="switch" lay-text="显示|隐藏"
                                       lay-filter="switchishead">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">占用宽度</label>
                            <div class="layui-input-block">
                                <input type="radio" name="width" value="200" title="200">
                                <input type="radio" name="width" value="250" title="250">
                                <input type="radio" name="width" value="300" title="300">
                                <input type="radio" name="width" value="350" title="350">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">存放位置</label>
                            <div class="layui-input-block">
                                <input type="radio" name="locations" value="1" title="基本信息" checked>
                                <input type="radio" name="locations" value="2" title="详细信息">
                                <input type="radio" name="locations" value="3" title="维护项目">
                                <input type="radio" name="locations" value="5" title="扩展信息">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <label class="layui-form-label">值唯一性</label>
                            <div class="layui-input-block">
                                <input type="radio" name="uniqueness" value="1" title="非唯一性" disabled>
                                <input type="radio" name="uniqueness" value="2" title="唯一性" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">创建时间</label>
                                <div class="layui-input-block">
                                    <input name="createTime" id="createTime" lay-verify="createTime" autocomplete="off"
                                           class="layui-input" type="text">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;padding: 0px;">
                                <button class="layui-btn" lay-submit lay-filter="*" id="pushButton">确认修改</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script>
    function child(d) {
        layui.use(['table', 'form', 'laydate', 'layer'], function () {
            var $ = layui.$
                , form = layui.form
                , laydate = layui.laydate,
                layer = layui.layer;
            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/rest/system/getOneStructure",
                data: "id=" + d,
                dataType: "json",
                async: false,
                success: function (data) {
                    form.val("component-form-element", data.data[0])
                    laydate.render({
                        elem: "#createTime",
                        btns: ['now', 'confirm'],
                        theme: 'molv',
                        calendar: true
                    });
                    if (data.data[0].type == "radio" || data.data[0].type == "textarea" || data.data[0].type == "checkbox" || data.data[0].type == "selects") {
                        $("#isValidates div").attr("class", "layui-unselect layui-form-switch");
                        $("#isValidates div em").text("否")
                        $("#isValidate").removeAttr('checked');
                        $('#isValidate').attr("disabled", true);
                        form.render();
                    } else {
                        $('#isValidate').attr("disabled", false);
                        form.render();
                    }
                    if (data.data[0].type == "datetime") {
                        $("#dataType").empty();
                        document.getElementById("dataType").options.add(new Option("datetime类型", "datetime"));
                        $("#dataType").val(data.data[0].dataType)
                        form.render('select');
                    } else if (data.data[0].type == "radio" || data.data[0].type == "textarea" || data.data[0].type == "checkbox" || data.data[0].type == "selects" || data.data[0].type == "select") {
                        $("#dataType").empty();
                        document.getElementById("dataType").options.add(new Option("String类型", "String"));
                        $("#dataType").val(data.data[0].dataType)
                        form.render('select');
                    } else if (data.data[0].type == "input") {
                        $("#dataType").empty();
                        if (data.data[0].dataType == "Double") {
                            document.getElementById("dataType").options.add(new Option("小数类型", "Double"));
                        } else  if (data.data[0].dataType == "Int") {
                            document.getElementById("dataType").options.add(new Option("整数类型", "Int"));
                        }else {
                            document.getElementById("dataType").options.add(new Option("String类型", "String"));
                        }
                        $("#dataType").val(data.data[0].dataType);
                        form.render('select');
                    }
                    if (data.data[0].type == "textarea") {
                        $("#headradios div").attr("class", "layui-unselect layui-form-switch");
                        $("#headradios div em").text("隐藏")
                        $("#headradio").removeAttr('checked');
                        $('#headradio').attr("disabled", true);
                        form.render();
                    } else {
                        $('#headradio').attr("disabled", false);
                        form.render();
                    }
                }
            })

            form.verify({
                oderNumber: function (value, item) {
                    if (value == "") {
                        return '请输入序号';
                    }
                },
            })

            //监听提交
            form.on('submit(*)', function (data) {
                var field = data.field//当前容器的全部表单字段，名值对形式：{name: value}
                var index = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.6});
                $("#pushButton").addClass("layui-btn layui-btn-disabled").prop("disabled", true);
                $.ajax({
                    type: "post",
                    url: "<%=request.getContextPath()%>/rest/system/updateStructure",
                    dataType: "json",
                    data: field,
                    async: false,
                    success: function (msg) {
                        setTimeout(function () {
                            layer.close(index);
                            if (msg == true) {
                                layer.msg('修改成功');
                            } else {
                                layer.msg(msg.errorMsg);
                            }
                        }, 2000);
                        setTimeout(function () {
                            var indexs = parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                            parent.layer.close(indexs);//关闭弹出层
                        }, 4000);

                    }
                })
                return false;
            })
        });
    }
</script>
</body>
</html>